package com.sushe;

import com.sushe.service.*;
import com.sushe.service.jiekou.*;

import java.sql.SQLException;
import java.util.Scanner;


public class Main {


    private static StudentService studentService=new StudentServiceImpl();
    private static RoomService roomService=new RoomServiceImpl();
    private static RoomDeleteService roomDeleteService=new RoomDeleteServiceImpl();
    private static BedAssignmentService bedAssignmentService=new BedAssignmentServiceImpl();
    private static RoomSwapService roomSwapService=new RoomSwapServiceImpl();
    private static DormBuildingService dormBuildingService=new DormBuildingServiceImpl();
    private static RoomQueryService roomQueryService=new RoomQueryServiceImpl();
    private static ShowAllStudentsService showAllStudentsService=new ShowAllStudentsServiceImpl();
    private static StudentDeleteService studentDeleteService=new StudentDeleteServiceImpl();
    private static StudentQueryService studentQueryService=new StudentQueryServiceImpl();
    private static RegisterService registerService=new RegisterServiceImpl();
    private static LoginService loginService=new LoginServiceImpl();
    private static ShowAllNoBedStudentsService showAllNoBedStudentsService=new ShowAllNoBedStudentsServiceImpl();

    public static void main(String[] args) throws SQLException, ClassNotFoundException {
        Scanner scanner = new Scanner(System.in);
        boolean running = true;
        boolean login = true;
        while (login) {
            System.out.println("\n===== 宿舍管理系统 =====");
            System.out.println("请选择登录或注册进入系统");
            System.out.println("1. 登录");
            System.out.println("2. 注册");
            System.out.println("0. 退出");
            System.out.print("请输入您的选择：");
            int choice = scanner.nextInt();
            switch (choice) {
                case 1:
                    int result =loginService.login();
                    if(result==1){
                        login=false;
                        break;
                    }
                    if(result==2){
                        break;
                    }
                case 2:
                    registerService.register();
                    break;
                case 0:
                    login=false;
                    running=false;
                    break;
                default:
                    System.out.println("无效选择！");
            }
        }

        while (running) {
            System.out.println("\n===== 宿舍管理系统 =====");
            System.out.println("1. 添加学生");
            System.out.println("2. 分配床位");
            System.out.println("3. 调换宿舍");
            System.out.println("4. 按宿舍查学生");
            System.out.println("5. 按学生查宿舍");
            System.out.println("6. 添加宿舍房间");//同时会自动添加宿舍房间中四个床位
            System.out.println("7. 添加宿舍楼");//添加宿舍楼信息
            System.out.println("8. 展示全部学生信息");
            System.out.println("9. 删除学生");
            System.out.println("10. 删除宿舍房间");
            System.out.println("11. 展示所有未分配床位的学生信息");
            System.out.println("0. 退出");
            System.out.print("请选择操作: ");

            int choice = scanner.nextInt();
            scanner.nextLine();  // 清除换行符

            switch (choice) {
                case 1:
                    studentService.addStudent();

                    break;
                case 2:
                    bedAssignmentService.bedAssignment();
                    break;
                case 3:
                    roomSwapService.roomSwap();
                    break;
                case 4:
                    studentQueryService.queryStudentByRoom();
                    break;
                case 5:
                    roomQueryService.queryRoomByStudent();
                    break;
                case 6:
                    roomService.addRoom();
                    break;
                case 7:
                    dormBuildingService.addDormBuilding();
                    break;
                case 8:
                    showAllStudentsService.showAllStudents();
                    break;
                case 9:
                    studentDeleteService.deleteStudent();
                    break;
                case 10:
                    roomDeleteService.deleteRoom();
                    break;
                case 11:
                    showAllNoBedStudentsService.showAllNoBedStudents();
                case 0:
                    running = false;
                    break;
                default:
                    System.out.println("无效选择");
            }
        }
        scanner.close();
        System.out.println("系统已退出");
    }
}